package charpter11.lynx;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class Nine{//这是因为原来的类结构就很不优雅，所以这个实现很难看
	private List<Object> items;

	public Nine() {
		items = new ArrayList<Object>();
	}

	public void add(Object x) {
		items.add(x);
	}

	private class SequenceSelector implements Selector {
		private ListIterator<Object> it = items.listIterator();
		private Object current = null;

		public boolean end() {
			return !it.hasNext();
		}

		public Object current() {
			if (current == null){
				if (it.hasNext()){
					current = it.next();
				}
			}
			return current;
		}

		public void next() {
			current = it.next();
		}
	}

	public Selector selector() {
		return new SequenceSelector();
	}

	public static void main(String[] args) {
		Three sequence = new Three();
		for (int i = 0; i < 10; i++)
			sequence.add(Integer.toString(i));
		Selector selector = sequence.selector();
		while (!selector.end()) {
			System.out.print(selector.current() + " ");
			selector.next();
		}
	}
}